package com.yuandian.management.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuandian.api.management.entity.ConfKeyword;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.management.mapper.ConfKeywordMapper;
import com.yuandian.management.service.ConfKeywordService;
import com.yuandian.management.vo.BusinessServerResourceParams;
import com.yuandian.management.vo.SegmentRelationByCodeVo;
import com.yuandian.management.vo.SysBusiRelationByCodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 识别关键字表-Service实现
 * @author zfsn
 * @date 2023-3-27
 */
@Service
public class ConfKeywordServiceImpl extends ServiceImpl<ConfKeywordMapper, ConfKeyword>
		implements ConfKeywordService {

	@Autowired
	private ConfKeywordMapper confKeywordMapper;
	/**
	 * 分页查询
	 *
	 * @param confKeyword 筛选条件
	 * @return 通用返回对象
	 */
	@Override
	public Page<ConfKeyword> listPage(ConfKeyword confKeyword) {
		return confKeywordMapper.listPage(new Page<>(confKeyword.getPageNum(), confKeyword.getPageSize()), confKeyword);
	}

	/**
	 * 新增数据
	 *
	 * @param confKeyword 实例对象
	 * @return 通用返回对象
	 */
	@Override
	public R<String> saveKeyWord(ConfKeyword confKeyword) {
		super.save(confKeyword);
		return R.ok();
	}

	/**
	 * 通过主键更新数据
	 *
	 * @param confKeyword 实例对象
	 * @return 通用返回对象
	 */
	@Override
	public R<String> updateKeyWordById(ConfKeyword confKeyword) {
		super.updateById(confKeyword);
		return R.ok();
	}

	@Override
	public List<ConfKeyword> selectByResourceCodes(List<String> list) {
		return confKeywordMapper.selectByResourceCodes(list);
	}

	@Override
	public Page<SysBusiRelationByCodeVo> querySysBusiRelationByResourceCode(BusinessServerResourceParams resourceParams) {
		if (resourceParams.getPageNum() == null || resourceParams.getPageSize() == null){
			resourceParams.setPageNum(1);
			resourceParams.setPageSize(10);
		}
		return confKeywordMapper.querySysBusiRelationByResourceCode(new Page<>(resourceParams.getPageNum(), resourceParams.getPageSize()), resourceParams);
	}

	/**
	 * 通过业务服务资源编码查询网端关联关系列表
	 *
	 * @param params 业务服务资源接口请求对象
	 * @return 通用返回对象
	 */
	@Override
	public Page<SegmentRelationByCodeVo> querySegmentRelationByResourceCode(BusinessServerResourceParams params) {
		Page<SegmentRelationByCodeVo> page = new Page<>(params.getPageNum(), params.getPageSize());
		page.setOptimizeCountSql(false);
		return confKeywordMapper.querySegmentRelationByResourceCode(page, params);
	}
}